package  app
{
	import app.model.vo.BallVO;
	import flash.display.MovieClip;
	import flash.events.Event;
	/**
	 * ...
	 * @author hungconcon
	 */
	[Embed(source="../../lib/embed/asset.swf", symbol="Ball")]
	public class Ball extends MovieClip
	{
		public var dots : MovieClip;
		
		public var rotationSpeed:int;
		public var radius:int;
		public var bounce:int;
		public var mass:int;
		public var vx:int;
		public var xmin:int;
		public var xmax:int;
		public var ymax:int;
		public var bumped:int;
		public var uda:int;
		public var udaswap:int;
		public var pass:int;
		public var swapdep:int;
		public var still:int;
		public var got:int;
		public var oldx:int;
		public var oldy:int;
		public var vy:int;
		public var vo:BallVO;
		
		public function Ball()  {
			var t:* = this;
			t.radius = Math.round(t.width / 2);
			t.bounce = 0.8;
			t.mass = 50;
			t.vx = 0;
			t.xmin = t.radius;
			t.xmax = App.screenwid - t.radius;
			t.ymax = App.yland - t.radius;
			t.bumped = t.uda = t.udaswap = t.pass = t.swapdep = t.still = t.got = 0;
		}
		public function delEnter():void {
			removeEventListener(Event.ENTER_FRAME, onEnterFrame);	
		}
		public function addEnter():void{
			addEventListener(Event.ENTER_FRAME, onEnterFrame);	
		}
		public function goingUp():void {
			x = App.p_x;
			y = App.p_y - 180;
			
			vx = 0;
			vy = 0 - (App.powermin + App.powerdiv * App.powerrange);
		}
		private function onEnterFrame(evt:Event):void {
			var t:* = this;
			oldx = x;
			oldy = y;
			vy = vy + App.grav;
			y = y + vy;
			x = x + vx;
			
			if (vy > 0) {
				//uda ? null : (uda = 1, App.balls.push(t));
				if (y < 250) {
					
					/*for (var i:int = 0; i < App.rings.length; i++) {
						
						var reg1:Ring = App.rings[i];
						
						if (Math.abs(reg1.y - y) < 60 && Math.abs(reg1.x - x) < 60) {
							
							if (t[reg1._name + "pass"] == undefined) {
								t[reg1._name + "pass"] = 0;
							} else if (t[reg1._name + "pass"] == 0) {
								if (hitTest(reg1.z1)) {
									
									t[reg1._name + "pass"] = 1;
									
									udaswap ? null : (udaswap = 1, swapDepths(dep - 20000));
								}
							} else if (t[reg1._name + "pass"] == 1) {
								if (hitTest(reg1.z2)) {
									reg1.got = 1;
									++got;
									reg1.netani = 3;
									 music
									t[reg1._name + "pass"] = 9;
								}
							}
							
						} else {
							t[reg1._name + "pass"] = undefined;
						}
					}*/
					
				}
			}
			if (vy > 0 && y > 250) {
				if (got > 1) {
					App.ang = App.ang + App.multiringscore[got];
					//popmultirings(x, 240, got); // gọi ra effect hiển thị kết quả
					//App.ztititink.start();
					got = 0;
				}
			}
			if (y > ymax) {
				bumped = 1;
				y = ymax;
				//vy <= 2 ? null : ballsfx(vy * 4);
				vy = -0.8 * vy;
				vx = 0.99 * vx;
			}
			if (x < xmin) {
				x = xmin;
				vx = -0.8 * vx;
			} else if (x > xmax) {
				x = xmax;
				vx = -0.8 * vx;
			}
			if (y == ymax) {
				Math.abs(oldx - x) < 1 && Math.abs(oldy - y) < 1 ? (still = 1) : (still = 0);
			}
		}
		public function rotational(step:Number):void {
			this.dots.rotation = this.dots.rotation + step;
		}
		
		public function set rotations(step:Number):void {
			this.dots.rotation = this.dots.rotation + step * rotationSpeed;
		}
		
	}

}